<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String id = request.getParameter("id") == null ? "" : request.getParameter("id");
    boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>

<html>
	<head>
		<title><%=isAdd?"新建材料":"编辑材料" %></title>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
	</head>
	<script type="text/javascript">	
		var flag = '<%=flag%>';
		$(function(){
			$('#unit_id').combobox({
				 url:'<%=contextPath %>/springMVC/group/getUnit',
				 valueField:'id',
				 textField:'name'
			});
			$("#material_type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=0',
				method:'POST',
				animate:true,
				lines:true
			});
			if(flag == '1'){
				$('#ff').form("load",'<%=contextPath %>/springMVC/warehouse/getMaterialById?id=<%=id%>');
			}
		});
		
		function doSubmit(obj){
			var material_type_id = $('#material_type_id').combotree('getValue');
			if(!checkNullOREmpty(material_type_id,"产品分类")){return;}
			var code = $('#code').val();
			var name = $('#name').val();
			if(!checkNullOREmpty(name,"产品名称")){return;}
			var format_type = $('#format_type').val();
			var unit_id = $('#unit_id').combobox('getValue');
			if(!checkNullOREmpty(unit_id,"计量单位")){return;}
			var unit_name = $('#unit_id').combobox('getText');
			var cost = $('#cost').numberbox('getValue');
			var param = "material_type_id="+material_type_id+"&code="+code+"&name="+name+"&format_type="+format_type+"&unit_id="+unit_id+"&unit_name="+unit_name+"&cost="+cost;
			$(obj).hide();
			if(flag == '0'){
				$.ajax({
					type:'POST',
					url:'<%=contextPath %>/springMVC/warehouse/addMaterial',
					data:param,
					success:function(rtJson){
						if (rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}else{
							$(obj).show();
							warningInfo(rtJson.rtMsrg);
						}
					}
				});
			}
			else{
				param=param+"&id=<%=id%>";
				$.ajax({
					type:'POST',
					url:'<%=contextPath %>/springMVC/warehouse/updateMaterial',
					data:param,
					success:function(rtJson){
						if (rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}else{
							$(obj).show();
							warningInfo(rtJson.rtMsrg);
						}
					}
				});
			}
		}
		
	</script>
	<body>
		<form id="ff" method="POST">
		<div style="width:90%;padding-left:50px;margin-top:50px">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
				<tr>
					<td align="right"  nowrap class="td1">
						分类：
					</td>
					<td class="td2" nowrap>
						<input  id="material_type_id" name="material_type_id" class="easyui-combotree"  data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right" nowrap class="td1">
						材料编号：
					</td>
					<td class="td2" nowrap>
						<input type="text" id="code" name="code" >
					</td>
				</tr>
				
				<tr>
					<td align="right"  nowrap class="td1">
						材料名称：
					</td>
					<td class="td2" nowrap >
						<input type="text" id="name" name="name"  class="easyui-validatebox" data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						规格型号：
					</td>
					<td class="td2" nowrap >
						<input id="format_type" name="format_type"/>
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						计量单位：
					</td>
					<td class="td2" nowrap >
						<input id="unit_id" name="unit_id" class="easyui-combobox" data-options="required:true"/>
					</td>
				</tr>
				<tr style="display:none;">
					<td align="right"  nowrap class="td1">
						价格：
					</td>
					<td class="td2" nowrap >
						<input id="cost" name="cost" class="easyui-numberbox" data-options=" min:0,precision:2" value="0"/>
					</td>
				</tr>
				<tr>
					<td align="right" nowrap class="td1">
					</td>
					<td  nowrap colspan="5">
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">保存</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
					</td>
				</tr>
				
 			</table>
		</div>
		</form>
	</body>
</html>
